<?php
/**
 * Description of commentController
 *
 * @author Henson
 */
class commentController{
	
    public function indexAction()
    {
		$comment = new Comment();
		if(_checkSuperLogin() && $comment->checkPermission())
		{
			$totalNum = $comment->getCommentTotal();
			$p = isset($_GET['p']) ? intval($_GET['p']) : 1;
			$pageUrl = '/index.php?r=comment';
			$page = new Page($p, $pageUrl, $totalNum, $comment->pageRow);
			$page->run();
			$rows = $comment->getCommentList($p);
			foreach($rows as $key=>$value)
			{
				$rows[$key] = $comment->dealComment($value);
			}
			$pageInfo['rows'] = $rows;
			$pageInfo['page'] = $page;
			$view = new view(); 
			$view->showPage('management/commentList.tpl.htm', $pageInfo);	
		}
    }
	
	public function genAction()
	{
		global $_CFG;
		$eid = @intval(trim($_POST['eid']));
		$content = @htmlspecialchars(trim($_POST['comment']), ENT_QUOTES);
		str_replace($_CFG['badwords'], '[censored]', $content, $count);
		if($count > 0)
		{
			_showMessage("评论成功！", '/index.php?r=event/show&eid='.$eid);
		}
		$insertArr = array();
		if($content && $eid > 0 && _checkLogin())
		{
			$insertArr['eid'] = $eid;
			$insertArr['content'] = $content;
			$insertArr['uid'] = $_COOKIE["uid"];
			$insertArr['username'] = $_COOKIE["username"];
			$comment = new Comment();
			if($comment->insertComment($insertArr))
			{
				_showMessage("评论成功！", '/index.php?r=event/show&eid='.$eid);
			}
			else
			{
				_showMessage("评论失败！", "back");
			}
		}
		else
		{
			_errorShow("comment is invalid");
		}
	}
}

?>
